using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VARDC
    {
        public DataRow Convert2ARDC(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryARDC(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ARCMANDANT"] = " ".PadRight(2 ); 
         dwReturn["ARCAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["ARCAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["ARCAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["ARCANSNR"] = " ".PadRight(0 ); 
         dwReturn["ARCABRNR"] = " ".PadRight(0 ); 
         dwReturn["ARCLFDNR"] = " ".PadRight(0 ); 
         dwReturn["ARCAENZL"] = " ".PadRight(0 ); 
         dwReturn["ARCAENB"] = " ".PadRight(8 ); 
         dwReturn["ARCAEND"] = " ".PadRight(0 ); 
         dwReturn["ARCNEUB"] = " ".PadRight(8 ); 
         dwReturn["ARCNEUD"] = " ".PadRight(0 ); 
         dwReturn["ARCAUFSTA"] = " ".PadRight(1 ); 
         dwReturn["ARCDOSYS"] = " ".PadRight(2 ); 
         dwReturn["ARCDOST"] = " ".PadRight(3 ); 
         dwReturn["ARCMKL"] = " ".PadRight(1 ); 
         dwReturn["ARCMAT"] = " ".PadRight(14 ); 
         dwReturn["ARCVAR"] = " ".PadRight(3 ); 
         dwReturn["ARCMATBEZ"] = " ".PadRight(25 ); 
         dwReturn["ARCKONZ"] = " ".PadRight(10 ); 
         dwReturn["ARCMEEH"] = " ".PadRight(4 ); 
         dwReturn["ARCMEGR"] = " ".PadRight(0 ); 
         dwReturn["ARCWGKZ"] = " ".PadRight(1 ); 
         dwReturn["ARCTOL"] = " ".PadRight(0 ); 
         dwReturn["ARCLTFG"] = " ".PadRight(0 ); 
         dwReturn["ARCDICHTE"] = " ".PadRight(0 ); 
         dwReturn["ARCGWMG"] = " ".PadRight(0 ); 
         dwReturn["ARCTRASH"] = " ".PadRight(0 ); 
         dwReturn["ARCSPLMG"] = " ".PadRight(0 ); 
         dwReturn["ARCLTR"] = " ".PadRight(1 ); 
         dwReturn["ARCFACT"] = " ".PadRight(1 ); 
         dwReturn["ARCCOR"] = " ".PadRight(1 ); 
         dwReturn["ARCFILLER"] = " ".PadRight(34 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapARDC(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveARDC(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryARDC(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapARDC(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertARDC(dwLocal, ITXDBVERSION);
            }
            UpdateARDC(dwLocal);
        }
        public void InsertARDC(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ARDC(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryARDC(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ARDC WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ARDC  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ARDC";
            Return = Result;
            return Return;
        }
        public void DeleteARDC(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ARDC   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateARDC(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ARDC SET "
                    +"ARCMANDANT= :ARCMANDANT,"
                    +"ARCAUFKRS= :ARCAUFKRS,"
                    +"ARCAUFLFD= :ARCAUFLFD,"
                    +"ARCAUFPOS= :ARCAUFPOS,"
                    +"ARCANSNR= :ARCANSNR,"
                    +"ARCABRNR= :ARCABRNR,"
                    +"ARCLFDNR= :ARCLFDNR,"
                    +"ARCAENZL= :ARCAENZL,"
                    +"ARCAENB= :ARCAENB,"
                    +"ARCAEND= :ARCAEND,"
                    +"ARCNEUB= :ARCNEUB,"
                    +"ARCNEUD= :ARCNEUD,"
                    +"ARCAUFSTA= :ARCAUFSTA,"
                    +"ARCDOSYS= :ARCDOSYS,"
                    +"ARCDOST= :ARCDOST,"
                    +"ARCMKL= :ARCMKL,"
                    +"ARCMAT= :ARCMAT,"
                    +"ARCVAR= :ARCVAR,"
                    +"ARCMATBEZ= :ARCMATBEZ,"
                    +"ARCKONZ= :ARCKONZ,"
                    +"ARCMEEH= :ARCMEEH,"
                    +"ARCMEGR= :ARCMEGR,"
                    +"ARCWGKZ= :ARCWGKZ,"
                    +"ARCTOL= :ARCTOL,"
                    +"ARCLTFG= :ARCLTFG,"
                    +"ARCDICHTE= :ARCDICHTE,"
                    +"ARCGWMG= :ARCGWMG,"
                    +"ARCTRASH= :ARCTRASH,"
                    +"ARCSPLMG= :ARCSPLMG,"
                    +"ARCLTR= :ARCLTR,"
                    +"ARCFACT= :ARCFACT,"
                    +"ARCCOR= :ARCCOR,"
                    +"ARCFILLER= :ARCFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ARCMANDANT", OracleType.NVarChar).Value = dwData["ARCMANDANT"].ToString(); 
          or1.Parameters.Add("ARCAUFKRS", OracleType.NVarChar).Value = dwData["ARCAUFKRS"].ToString(); 
          or1.Parameters.Add("ARCAUFLFD", OracleType.NVarChar).Value = dwData["ARCAUFLFD"].ToString(); 
          or1.Parameters.Add("ARCAUFPOS", OracleType.NVarChar).Value = dwData["ARCAUFPOS"].ToString(); 
          or1.Parameters.Add("ARCANSNR", OracleType.NVarChar).Value = dwData["ARCANSNR"].ToString(); 
          or1.Parameters.Add("ARCABRNR", OracleType.NVarChar).Value = dwData["ARCABRNR"].ToString(); 
          or1.Parameters.Add("ARCLFDNR", OracleType.NVarChar).Value = dwData["ARCLFDNR"].ToString(); 
          or1.Parameters.Add("ARCAENZL", OracleType.NVarChar).Value = dwData["ARCAENZL"].ToString(); 
          or1.Parameters.Add("ARCAENB", OracleType.NVarChar).Value = dwData["ARCAENB"].ToString(); 
          or1.Parameters.Add("ARCAEND", OracleType.NVarChar).Value = dwData["ARCAEND"].ToString(); 
          or1.Parameters.Add("ARCNEUB", OracleType.NVarChar).Value = dwData["ARCNEUB"].ToString(); 
          or1.Parameters.Add("ARCNEUD", OracleType.NVarChar).Value = dwData["ARCNEUD"].ToString(); 
          or1.Parameters.Add("ARCAUFSTA", OracleType.NVarChar).Value = dwData["ARCAUFSTA"].ToString(); 
          or1.Parameters.Add("ARCDOSYS", OracleType.NVarChar).Value = dwData["ARCDOSYS"].ToString(); 
          or1.Parameters.Add("ARCDOST", OracleType.NVarChar).Value = dwData["ARCDOST"].ToString(); 
          or1.Parameters.Add("ARCMKL", OracleType.NVarChar).Value = dwData["ARCMKL"].ToString(); 
          or1.Parameters.Add("ARCMAT", OracleType.NVarChar).Value = dwData["ARCMAT"].ToString(); 
          or1.Parameters.Add("ARCVAR", OracleType.NVarChar).Value = dwData["ARCVAR"].ToString(); 
          or1.Parameters.Add("ARCMATBEZ", OracleType.NVarChar).Value = dwData["ARCMATBEZ"].ToString(); 
          or1.Parameters.Add("ARCKONZ", OracleType.NVarChar).Value = dwData["ARCKONZ"].ToString(); 
          or1.Parameters.Add("ARCMEEH", OracleType.NVarChar).Value = dwData["ARCMEEH"].ToString(); 
          or1.Parameters.Add("ARCMEGR", OracleType.NVarChar).Value = dwData["ARCMEGR"].ToString(); 
          or1.Parameters.Add("ARCWGKZ", OracleType.NVarChar).Value = dwData["ARCWGKZ"].ToString(); 
          or1.Parameters.Add("ARCTOL", OracleType.NVarChar).Value = dwData["ARCTOL"].ToString(); 
          or1.Parameters.Add("ARCLTFG", OracleType.NVarChar).Value = dwData["ARCLTFG"].ToString(); 
          or1.Parameters.Add("ARCDICHTE", OracleType.NVarChar).Value = dwData["ARCDICHTE"].ToString(); 
          or1.Parameters.Add("ARCGWMG", OracleType.NVarChar).Value = dwData["ARCGWMG"].ToString(); 
          or1.Parameters.Add("ARCTRASH", OracleType.NVarChar).Value = dwData["ARCTRASH"].ToString(); 
          or1.Parameters.Add("ARCSPLMG", OracleType.NVarChar).Value = dwData["ARCSPLMG"].ToString(); 
          or1.Parameters.Add("ARCLTR", OracleType.NVarChar).Value = dwData["ARCLTR"].ToString(); 
          or1.Parameters.Add("ARCFACT", OracleType.NVarChar).Value = dwData["ARCFACT"].ToString(); 
          or1.Parameters.Add("ARCCOR", OracleType.NVarChar).Value = dwData["ARCCOR"].ToString(); 
          or1.Parameters.Add("ARCFILLER", OracleType.NVarChar).Value = dwData["ARCFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
